package com.guli.gulimall.gulimallproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.guli.gulimall.gulimallproduct.vo.spuvo.SpuSaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guli.gulimall.gulimallproduct.entity.SpuInfoEntity;
import com.guli.gulimall.gulimallproduct.service.SpuInfoService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * spu信息
 *
 * @author zouzhi
 * @email 1245268075@qq.com
 * @date 2022-04-03 10:19:08
 */
@RestController
@RequestMapping("gulimallproduct/spuinfo")
@Api(value = "SpuInfoController 接口",tags = "spu信息")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = spuInfoService.queryPage(params);
        PageUtils page = spuInfoService.queryPageByCondition(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
//    @PostMapping("/save")
//    public R save(@RequestBody SpuInfoEntity spuInfo){
//		spuInfoService.save(spuInfo);
//
//        return R.ok();
//    }
    @PostMapping("/save")
    @ApiOperation("保存整个商品信息")
    public R save(@RequestBody SpuSaveVo skuInfoVo){
        System.out.println(skuInfoVo);
        spuInfoService.saveSpuInfo(skuInfoVo);
        return R.ok();
    }
    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 商品上架功能
     */
    @PostMapping("{spuId}/up")
    @ApiOperation("商品上架功能")
    public R  productUp(@PathVariable Long spuId){
        return  spuInfoService.productUp(spuId);
    }

}
